package com.lanjiu.lib.imclient.dto.chat;

import com.lanjiu.pro.business.BusinessProtocolEntities;
import com.lanjiu.lib.imclient.dto.base.Dto;
import com.lanjiu.lib.imclient.ims.IMSContacts;

/**
 * @description:
 * @author: Panwei
 * @date: 2019/11/14 21:24
 */
public class ChatMessageDto extends Dto {

    // 消息ID
    private String msgId;

    // 消息内容类型(图片/视频/文本/语音/文件)
    private int chatType;

    // 文本实体
    private TextDto text;

    // 图片实体
    private PictureDto picture;

    // 视频实体
    private VideoDto video;

    // 语音实体
    private VoiceDto voice;

    // 文件实体
    private FileDto file;

    public ChatMessageDto() {
    }

    public String getMsgId() {
        return msgId;
    }

    public void setMsgId(String msgId) {
        this.msgId = msgId;
    }

    public int getChatType() {
        return chatType;
    }

    public void setChatType(int chatType) {
        this.chatType = chatType;
    }

    public TextDto getText() {
        return text;
    }

    public void setText(TextDto text) {
        this.text = text;
    }

    public PictureDto getPicture() {
        return picture;
    }

    public void setPicture(PictureDto picture) {
        this.picture = picture;
    }

    public VideoDto getVideo() {
        return video;
    }

    public void setVideo(VideoDto video) {
        this.video = video;
    }

    public VoiceDto getVoice() {
        return voice;
    }

    public void setVoice(VoiceDto voice) {
        this.voice = voice;
    }

    public FileDto getFile() {
        return file;
    }

    public void setFile(FileDto file) {
        this.file = file;
    }

    public ChatMessageDto(BusinessProtocolEntities.ChatMessage chatMessage, String path) {
        this.msgId = chatMessage.getMsgId();
        this.chatType = chatMessage.getChatType();
        if (chatType == IMSContacts.MsgContentType.TEXT
                || chatType == IMSContacts.MsgContentType.APPLY_TOURISTS
                || chatType == IMSContacts.MsgContentType.APPLY_REGISTERED
                || chatType == IMSContacts.MsgContentType.APPLY_REFUSE_TOURISTS
                || chatType == IMSContacts.MsgContentType.APPLY_REFUSE_REGISTERED
                || chatType == IMSContacts.MsgContentType.INVITE_REFUSE_TOURISTS
                || chatType == IMSContacts.MsgContentType.INVITE_REFUSE_REGISTERED
                || chatType == IMSContacts.MsgContentType.INVITE_TOURISTS
                || chatType == IMSContacts.MsgContentType.INVITE_REGISTERED
                || chatType == IMSContacts.MsgContentType.APPLY_FRIEND_TOURISTS
                || chatType == IMSContacts.MsgContentType.APPLY_FRIEND_REGISTERED
                || chatType == IMSContacts.MsgContentType.APPLY_REFUSE_FRIEND_TOURISTS
                || chatType == IMSContacts.MsgContentType.APPLY_REFUSE_FRIEND_REGISTERED
                || chatType == IMSContacts.MsgContentType.DELETE_GROUP_MEMBER
                || chatType == IMSContacts.MsgContentType.EXIT_GROUP
                || chatType == IMSContacts.MsgContentType.DISSOLVE_GROUP)
            this.text = new TextDto(chatMessage.getText());
        else if (chatType == IMSContacts.MsgContentType.PICTURE)
            this.picture = new PictureDto(chatMessage.getPicture(), path);
        else if (chatType == IMSContacts.MsgContentType.VIDEO)
            this.video = new VideoDto(chatMessage.getVideo(), path);
        else if (chatType == IMSContacts.MsgContentType.VOICE)
            this.voice = new VoiceDto(chatMessage.getVoice(), path);
        else if (chatType == IMSContacts.MsgContentType.FILE)
            this.file = new FileDto(chatMessage.getFile());
    }

    @Override
    public BusinessProtocolEntities.ChatMessage toProtobuf() {
        BusinessProtocolEntities.ChatMessage.Builder builder = BusinessProtocolEntities.ChatMessage.newBuilder();
        if (null != msgId) builder.setMsgId(msgId);
        builder.setChatType(chatType);
        if (chatType == IMSContacts.MsgContentType.TEXT
                || chatType == IMSContacts.MsgContentType.APPLY_TOURISTS
                || chatType == IMSContacts.MsgContentType.APPLY_REGISTERED
                || chatType == IMSContacts.MsgContentType.APPLY_REFUSE_TOURISTS
                || chatType == IMSContacts.MsgContentType.APPLY_REFUSE_REGISTERED
                || chatType == IMSContacts.MsgContentType.INVITE_REFUSE_TOURISTS
                || chatType == IMSContacts.MsgContentType.INVITE_REFUSE_REGISTERED
                || chatType == IMSContacts.MsgContentType.INVITE_TOURISTS
                || chatType == IMSContacts.MsgContentType.INVITE_REGISTERED
                || chatType == IMSContacts.MsgContentType.APPLY_FRIEND_TOURISTS
                || chatType == IMSContacts.MsgContentType.APPLY_FRIEND_REGISTERED
                || chatType == IMSContacts.MsgContentType.APPLY_REFUSE_FRIEND_TOURISTS
                || chatType == IMSContacts.MsgContentType.APPLY_REFUSE_FRIEND_REGISTERED
                || chatType == IMSContacts.MsgContentType.DELETE_GROUP_MEMBER
                || chatType == IMSContacts.MsgContentType.EXIT_GROUP
                || chatType == IMSContacts.MsgContentType.DISSOLVE_GROUP) {
            if (null != text)
                builder.setText(text.toProtobuf());
        } else if (chatType == IMSContacts.MsgContentType.PICTURE && null != picture) {
            builder.setPicture(picture.toProtobuf());
        } else if (chatType == IMSContacts.MsgContentType.VIDEO && null != video) {
            builder.setVideo(video.toProtobuf());
        } else if (chatType == IMSContacts.MsgContentType.VOICE && null != voice) {
            builder.setVoice(voice.toProtobuf());
        } else if (chatType == IMSContacts.MsgContentType.FILE && null != file) {
            builder.setFile(file.toProtobuf());
        }
        return builder.build();
    }
}
